<template>
  <div class="order-item">
    <div class="title">
      <div class="select">
        <el-checkbox v-model="select"></el-checkbox>
      </div>
      <div class="time">
        {{ dayjs(order.add_time).format("YYYY-MM-DD HH:MM:ss") }}
      </div>
      <div class="number">
        <span>订单编号：</span><b>{{ order.order_number }}</b>
      </div>
      <img
        :src="order.shop_img"
        @click="toShopPage(order.shop_id)"
        alt=""
        class="shop-img"
      />
      <div class="name" @click="toShopPage(order.shop_id)">
        {{ order.shop_name }}
      </div>
    </div>
    <div class="order-info">
      <div class="goods-list">
        <div
          class="goods-item"
          v-for="(goods, index) in order.orderdetail"
          :key="index"
        >
          <img :src="goods.banner" alt="" />
          <div class="text">
            <div class="tit">{{ goods.good_name }}</div>
            <div class="spec">{{ goods.name }}</div>
          </div>
          <div class="price">
            <b>￥{{ goods.price }}</b>
            <s>￥{{ goods.price }}</s>
          </div>
          <div class="num">&times; {{ goods.goods_quantity }}</div>
        </div>
      </div>
      <div class="total-price">
        <b>￥{{ order.total }}</b>
        <!-- <span>含运费：8.00</span>
        <span>满减：10.00</span> -->
      </div>
      <div class="order-status" v-if="order.status < 6">
        <span class="status" v-if="order.status == 0">待确认</span>
        <span class="status" v-else-if="order.status == 1">待发货</span>
        <span class="status" v-else-if="order.status == 2">待收货</span>
        <span class="status" v-else-if="order.status == 3">已完成 </span>
        <span class="status" v-else-if="order.status == 4">已取消</span>
        <span class="status" v-else-if="order.status == 6">提交申请</span>
        <span @click="toOrderDetailId(order.order_number)">订单详情</span>
      </div>
      <div class="order-action">
        <el-button
          @click="enterOrder(order)"
          class="action"
          type="primary"
          v-if="order.status == 0"
        >
          确认下单
        </el-button>
        <el-button
          @click="clearOrder(order)"
          class="action"
          type="primary"
          v-else-if="order.status == 1"
        >
          取消订单
        </el-button>
        <div class="duo_btn" v-else-if="order.status == 2">
          <el-button @click="expressInfo(order)" class="action" type="text">
            物流信息
          </el-button>
          <el-button @click="receiptOrder(order)" class="action" type="primary">
            确认收货
          </el-button>
        </div>
        <div class="duo_btn" v-else-if="order.status == 3">
          <el-button
            v-if="
              order.closeaftermarket_time &&
              Date.now() > order.closeaftermarket_time
            "
            type="text"
          >
            已完成
          </el-button>
          <el-button @click="refundOrder(order)" class="action" type="primary">
            申请售后
          </el-button>
        </div>
        <span class="status" v-else-if="order.status == 6">提交申请</span>
        <span class="status" v-else-if="order.status == 7">处理中</span>
        <span class="status" v-else-if="order.status == 8">处理完成</span>
        <el-button class="clear" type="text" v-else> 已取消 </el-button>
      </div>
    </div>
  </div>
</template>

<script>
import api from "@/api";
import dayjs from "dayjs";

export default {
  name: "OrderItem",
  props: {
    order: Object,
  },
  data() {
    return {
      dayjs,
      select: false,
    };
  },
  methods: {
    // 确认订单
    async enterOrder(order) {
      let loading = this.loadingMsg();
      await api.ORDER_DETERMINE([order.order_number]);
      loading.close();
      Object.assign(order, { status: 1 });
      this.$message.success("确认成功");
    },
    // 取消订单
    async clearOrder(order) {
      let loading = this.loadingMsg();
      await api.ORDER_CLEAR(order.order_number);
      loading.close();
      Object.assign(order, { status: 4 });
      this.$message.success("确认成功");
      this.$emit("change");
    },
    // 提醒订单
    remindOrder(order) {
      console.log(order);
      this.$message.success("提醒发货");
    },
    // 快递信息
    expressInfo(order) {
      console.log(order);
      this.$message.success("快递信息");
    },
    // 确认收货
    receiptOrder(order) {
      console.log(order);
      this.$message.success("确认收货");
    },
    // 退款售后
    refundOrder(order) {
      // console.log(order);
      this.addOrderSaleafter(order.order_number);
      // this.$message.success("退款售后");
    },
  },
};
</script>

<style lang="scss" scoped>
.order-item {
  margin-bottom: 20px;
  .title {
    height: 36px;
    background: #f3f5f9;
    border: 1px solid #f0f0f0;
    display: flex;
    align-items: center;
    .select {
      margin: 0 0 0 20px;
    }
    .time {
      margin: 0 16px;
      font-size: 16px;
      color: #666666;
    }
    .number {
      font-size: 16px;
      color: #333333;
      margin-right: 20px;
    }
    .shop-img {
      width: 28px;
      height: 28px;
      border-radius: 5px;
      margin-right: 12px;
    }
    .name {
      font-size: 16px;
      font-weight: 600;
      color: #333333;
    }
  }
  .order-info {
    display: flex;
    border: 1px solid #dedede;
    .goods-list {
      flex: 1;
      width: 0;
      border-right: 1px solid #dedede;
      .goods-item {
        display: flex;
        padding: 20px;
        img {
          margin-right: 12px;
          width: 78px;
          height: 78px;
          border-radius: 5px;
        }
        .text {
          flex: 1;
          width: 0;
          margin-right: 40px;
          .tit {
            font-size: 14px;
            color: #333333;
            line-height: 20px;
            height: 40px;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
          }
          .spec {
            margin-top: 12px;
            font-size: 14px;
            color: #666666;
            line-height: 20px;
          }
        }
        .price {
          margin-right: 20px;
          font-size: 14px;
          color: #333333;
          line-height: 20px;
          display: flex;
          flex-direction: column;
          width: 60px;
          align-items: flex-end;
        }
      }
    }
    .total-price {
      width: 180px;
      border-right: 1px solid #dedede;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      b {
        font-size: 20px;
        font-weight: 600;
        color: #333333;
        line-height: 28px;
        margin-bottom: 12px;
      }
      span {
        font-size: 14px;
        color: #666666;
        line-height: 20px;
      }
    }
    .order-status {
      width: 140px;
      border-right: 1px solid #dedede;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      font-size: 16px;
      color: #333333;
      line-height: 22px;
      .status {
        margin-bottom: 12px;
      }
      span {
        cursor: pointer;
      }
    }
    .order-action {
      width: 160px;
      border-right: 1px solid #dedede;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      .duo_btn {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        ::v-deep {
          .el-button {
            margin-left: 0;
          }
        }
      }
      .action {
        width: 120px;
        height: 40px;
      }
      .clear {
        color: #666666;
      }
    }
  }
}
</style>
